<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="robot" content="index,follow">
<title>Module xos - XML/HTML writer - Forth Foundation Library</title>
</head>
<body>
<h2>xos - XML/HTML writer</h2>
<h3>Module Description</h3>
<p>The xos module implements an xml and html writer. The xos module extends
the tos module with extra words, so the xos words work on tos variables.
The module translates the normal entity references: &lt;, &gt;, &quot;,
&amp; and '. All other entity references should be written with the word
xos-write-raw-text. Note: balancing of start and end tags is not checked,
so the module can also be used to write html output.
</p>
<h3>Module Words</h3>
<dl>
</dl>
<h4>xml writer words</h4>
<dl>
<dt><a name="word1"><b>xos-write-start-xml</b>	( c-addr1 u1 ... c-addr2n u2n n tos -- )</dt>
<dd>Write the start of a xml document with n attributes and values</dd>
<dt><a name="word2"><b>xos-write-text</b>	( c-addr u tos -- )</dt>
<dd>Write normal xml text c-addr u with translation to the default entity references</dd>
<dt><a name="word3"><b>xos-write-start-tag</b>	( c-addr1 u1 ... c-addr2n u2n n c-addr u tos -- )</dt>
<dd>Write the xml start tag c-addr u with n attributes and values c-addr* u*</dd>
<dt><a name="word4"><b>xos-write-end-tag</b>	( c-addr u tos -- )</dt>
<dd>Write the xml end tag c-addr u</dd>
<dt><a name="word5"><b>xos-write-empty-element</b>	( c-addr1 u1 ... c-addr2n u2n n c-addr u tos -- )</dt>
<dd>Write the xml start and end tag c-addr u with n attributes and values c-addr* u*</dd>
<dt><a name="word6"><b>xos-write-raw-text</b>	( c-addr u tos -- )</dt>
<dd>Write unprocessed xml text</dd>
<dt><a name="word7"><b>xos-write-comment</b>	( c-addr u tos -- )</dt>
<dd>Write a xml comment</dd>
<dt><a name="word8"><b>xos-write-cdata</b>	( c-addr u tos -- )</dt>
<dd>Write a xml CDATA section</dd>
<dt><a name="word9"><b>xos-write-proc-instr</b>	( c-addr1 u1 c-addr2n u2n n c-addr u tos -- )</dt>
<dd>Write a xml processing instruction with target c-addr u and n attributes and values c-addr* u*</dd>
<dt><a name="word10"><b>xos-write-internal-dtd</b>	( c-addr1 u1 c-addr2 u2 tos -- )</dt>
<dd>Write an internal document type definition with name c-addr2 u2 and markup c-addr1 u1</dd>
<dt><a name="word11"><b>xos-write-system-dtd</b>	( c-addr1 u1 c-addr2 u2 c-addr3 u3 tos -- )</dt>
<dd>Write a system document type definition with name c-addr3 u3, markup c-addr2 u2 and system c-addr1 u1</dd>
<dt><a name="word12"><b>xos-write-public-dtd</b>	( c-addr1 u1 c-addr2 u2 c-addr3 u3 c-addr4 u4 tos -- )</dt>
<dd>Write a public document type definition with name c-addr4 u4, markup c-addr3 u3, public-id c-addr2 u2 and system c-addr1 u1</dd>
</dl>
<h3>Examples</h3>
<pre>
include ffl/xos.fs


\ Example 1: Write xml output


\ Create the xml output stream

tos-create xos1

s" encoding" s" ISO-8859-1" s" version" s" 1.0" 2 xos1 xos-write-start-xml

s"  menu of the day " xos1 xos-write-comment

0 s" menu"         xos1 xos-write-start-tag
0 s" food"         xos1 xos-write-start-tag
0 s" name"         xos1 xos-write-start-tag
  s" Breakfast"    xos1 xos-write-text
  s" name"         xos1 xos-write-end-tag
0 s" description"  xos1 xos-write-start-tag
  s" two eggs &amp; bacon or sausage &amp; toast &amp; hash browns" xos1 xos-write-text
  s" description"  xos1 xos-write-end-tag
0 s" price"        xos1 xos-write-start-tag
  s" $6.95"        xos1 xos-write-text
  s" price"        xos1 xos-write-end-tag
s" cholesterol" s" yes"
1 s" health"       xos1 xos-write-empty-element
  s" food"         xos1 xos-write-end-tag
  s" menu"         xos1 xos-write-end-tag


xos1 str-get type cr                 \ Type the xml info


\ Example 2: Write html output


xos1 tos-rewrite                     \ Clean the output stream

nil 0 s" -//W3C//DTD HTML 4.0 Transitional//EN" nil 0 s" HTML" xos1 xos-write-public-dtd

0 s" HTML"         xos1 xos-write-start-tag
0 s" HEAD"         xos1 xos-write-start-tag
0 s" TITLE"        xos1 xos-write-start-tag
  s" HTML example" xos1 xos-write-text
  s" TITLE"        xos1 xos-write-end-tag
0 s" BODY"         xos1 xos-write-start-tag
0 s" H1"           xos1 xos-write-start-tag
  s" 'Welcome'"    xos1 xos-write-text          \ Translate ' to &amp;apos;
  s" H1"           xos1 xos-write-end-tag
  s"  comment "    xos1 xos-write-comment
  
  s" align" s" center"
1 s" DIV"          xos1 xos-write-start-tag     \ = &lt;DIV align="center"&gt;

  s" Test"         xos1 xos-write-text
  s" DIV"          xos1 xos-write-end-tag
  s" BODY"         xos1 xos-write-end-tag
  s" HTML"         xos1 xos-write-end-tag
  
xos1 str-get type cr
</pre>
<hr>
<div align="center">generated 24-Jul-2010 by <b>ofcfrth-0.10.0</b></div>
</body>
</html>
